import 'package:finance_app/src/entities/services_entity.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';

servicesEntityFromJson(ServicesEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['category_id'] != null) {
		data.categoryId = json['category_id'];
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['code'] != null) {
		data.code = json['code'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['enable_sell'] != null) {
		data.enableSell = json['enable_sell'] is String
				? int.tryParse(json['enable_sell'])
				: json['enable_sell'].toInt();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['tax_id'] != null) {
		data.taxId = json['tax_id'] is String
				? int.tryParse(json['tax_id'])
				: json['tax_id'].toInt();
	}
	if (json['price'] != null) {
		data.price = json['price'] is String
				? num.tryParse(json['price'])
				: json['price'];
	}
	if (json['is_tax_inclusive'] != null) {
		data.isTaxInclusive = json['is_tax_inclusive'] is String
				? int.tryParse(json['is_tax_inclusive'])
				: json['is_tax_inclusive'].toInt();
	}
	if (json['enable_purchase'] != null) {
		data.enablePurchase = json['enable_purchase'] is String
				? int.tryParse(json['enable_purchase'])
				: json['enable_purchase'].toInt();
	}
	if (json['purchase_currency_code'] != null) {
		data.purchaseCurrencyCode = json['purchase_currency_code'].toString();
	}
	if (json['purchase_price'] != null) {
		data.purchasePrice = json['purchase_price'] is String
				? num.tryParse(json['purchase_price'])
				: json['purchase_price'];
	}
	if (json['purchase_tax_id'] != null) {
		data.purchaseTaxId = json['purchase_tax_id'] is String
				? int.tryParse(json['purchase_tax_id'])
				: json['purchase_tax_id'].toInt();
	}
	if (json['purchase_is_tax_inclusive'] != null) {
		data.purchaseIsTaxInclusive = json['purchase_is_tax_inclusive'] is String
				? int.tryParse(json['purchase_is_tax_inclusive'])
				: json['purchase_is_tax_inclusive'].toInt();
	}
	if (json['is_activated'] != null) {
		data.isActivated = json['is_activated'] is String
				? int.tryParse(json['is_activated'])
				: json['is_activated'].toInt();
	}
	if (json['enabled'] != null) {
		data.enabled = json['enabled'] is String
				? int.tryParse(json['enabled'])
				: json['enabled'].toInt();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['tax'] != null) {
		data.tax = SettingDataTax().fromJson(json['tax']);
	}
	if (json['purchase_tax'] != null) {
		data.purchaseTax = SettingDataTax().fromJson(json['purchase_tax']);
	}
	if (json['discount_type'] != null) {
		data.discountType = json['discount_type'].toString();
	}
	if (json['discount_value'] != null) {
		data.discountValue = json['discount_value'] is String
				? num.tryParse(json['discount_value'])
				: json['discount_value'];
	}
	if (json['categories'] != null) {
		data.categories = (json['categories'] as List).map((v) => v.toString()).toList().cast<String>();
	}
	if (json['attachments'] != null) {
		data.attachments = (json['attachments'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> servicesEntityToJson(ServicesEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['category_id'] = entity.categoryId;
	data['name'] = entity.name;
	data['code'] = entity.code;
	data['description'] = entity.description;
	data['enable_sell'] = entity.enableSell;
	data['currency_code'] = entity.currencyCode;
	data['tax_id'] = entity.taxId;
	data['price'] = entity.price;
	data['is_tax_inclusive'] = entity.isTaxInclusive;
	data['enable_purchase'] = entity.enablePurchase;
	data['purchase_currency_code'] = entity.purchaseCurrencyCode;
	data['purchase_price'] = entity.purchasePrice;
	data['purchase_tax_id'] = entity.purchaseTaxId;
	data['purchase_is_tax_inclusive'] = entity.purchaseIsTaxInclusive;
	data['is_activated'] = entity.isActivated;
	data['enabled'] = entity.enabled;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['tax'] = entity.tax?.toJson();
	data['purchase_tax'] = entity.purchaseTax?.toJson();
	data['discount_type'] = entity.discountType;
	data['discount_value'] = entity.discountValue;
	data['categories'] = entity.categories;
	data['attachments'] =  entity.attachments?.map((v) => v.toJson())?.toList();
	return data;
}